package com.chia.multienty.core.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.chia.multienty.core.annotation.WebLog;
import com.chia.multienty.core.domain.basic.Result;
import com.chia.multienty.core.domain.dto.WorkflowProcessDTO;
import com.chia.multienty.core.parameter.workflow.*;
import com.chia.multienty.core.pojo.ProcessType;
import com.chia.multienty.core.service.ProcessTypeService;
import com.chia.multienty.core.service.WorkflowProcessService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 流程 服务
 * </p>
 *
 * @author Multienty Auto Generator
 * @since 2024-05-14
 */
@RestController
@Validated
@RequestMapping("/workflow-process")
@RequiredArgsConstructor
@Api(tags = "流程")
public class WorkflowProcessController {

    private final WorkflowProcessService workflowProcessService;
    private final ProcessTypeService processTypeService;
    @PostMapping("/detail")
    @ApiOperation("获取流程详情")
    public Result<WorkflowProcessDTO> getDetail(@Validated @RequestBody WorkflowProcessDetailGetParameter parameter) {
        WorkflowProcessDTO detail = workflowProcessService.getDetail(parameter);
        return new Result<>(detail);
    }

    @PostMapping("/page")
    @ApiOperation("获取流程分页列表")
    public Result<IPage<WorkflowProcessDTO>> getPage(@Validated @RequestBody WorkflowProcessPageGetParameter parameter) {
        IPage<WorkflowProcessDTO> page = workflowProcessService.getPage(parameter);
        return new Result<>(page);
    }

    @PostMapping("/update")
    @ApiOperation("更新流程")
    @WebLog(target = "WorkflowProcess")
    public Result<Boolean> update(@Validated @RequestBody WorkflowProcessUpdateParameter parameter) {
        workflowProcessService.update(parameter);
        return new Result<>(true);
    }
    @GetMapping("/types/get")
    @ApiOperation("获取流程类型列表")
    public Result<List<ProcessType>> getTypes() {
        return new Result<>(processTypeService.getAll());
    }

    @PostMapping("/save")
    @ApiOperation("保存流程")
    @WebLog(target = "WorkflowProcess")
    public Result<Boolean> save(@Validated @RequestBody WorkflowProcessSaveParameter parameter) {
        workflowProcessService.save(parameter);
        return new Result<>(true);
    }

    @PostMapping("/enable")
    @ApiOperation("启用流程")
    @WebLog(target = "WorkflowProcess")
    public Result<Boolean> enable(@Validated @RequestBody WorkflowProcessEnableParameter parameter) {
        workflowProcessService.enable(parameter);
        return new Result<>(true);
    }

    @PostMapping("/updateXml")
    @ApiOperation("修改流程Xml文件")
    @WebLog(target = "WorkflowProcess")
    public Result<Boolean> updateXml(@Validated @RequestBody WorkflowProcessXmlUpdateParameter parameter) {
        workflowProcessService.updateXml(parameter);
        return new Result<>(true);
    }

    @PostMapping("/deploy")
    @ApiOperation("部署流程")
    @WebLog(target = "WorkflowProcess")
    public Result<Boolean> deploy(@Validated @RequestBody WorkflowProcessDeployParameter parameter) {
        workflowProcessService.deploy(parameter);
        return new Result<>(true);
    }

    @PostMapping("/redeploy")
    @ApiOperation("重新部署流程")
    @WebLog(target = "WorkflowProcess")
    public Result<Boolean> redeploy(@Validated @RequestBody WorkflowProcessRedeployParameter parameter) {
        workflowProcessService.redeploy(parameter);
        return new Result<>(true);
    }

    @PostMapping("/disable")
    @ApiOperation("禁用流程")
    @WebLog(target = "WorkflowProcess")
    public Result<Boolean> disable(@Validated @RequestBody WorkflowProcessDisableParameter parameter) {
        workflowProcessService.disable(parameter);
        return new Result<>(true);
    }

    @DeleteMapping("/delete")
    @ApiOperation("删除流程")
    @WebLog(target = "WorkflowProcess")
    public Result<Boolean> delete(@Validated @RequestBody WorkflowProcessDeleteParameter parameter) {
        workflowProcessService.delete(parameter);
        return new Result<>(true);
    }

}
